<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">
  <meta name="baidu-site-verification" content="code-oLqr5o013S">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"shaojunying.github.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":true,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="字典的实现字典的底层是基于哈希表实现的,哈希表中的每一个节点保存了字典的一个键值对 哈希表的实现12345678910struct dictht&amp;#123;    &#x2F;&#x2F; 数组,存储哈希表中的节点    dictEntry ** table;    &#x2F;&#x2F; 数组的大小    unsigned long size;    &#x2F;&#x2F; 掩码 用于计算索引值    unsigned long sizemask;">
<meta property="og:type" content="article">
<meta property="og:title" content="Redis中的字典">
<meta property="og:url" content="https://shaojunying.github.io/2020/10/27/Redis%E4%B8%AD%E5%AD%97%E5%85%B8%E7%9A%84%E5%AE%9E%E7%8E%B0/index.html">
<meta property="og:site_name" content="Shaojunying&#39;s Blog">
<meta property="og:description" content="字典的实现字典的底层是基于哈希表实现的,哈希表中的每一个节点保存了字典的一个键值对 哈希表的实现12345678910struct dictht&amp;#123;    &#x2F;&#x2F; 数组,存储哈希表中的节点    dictEntry ** table;    &#x2F;&#x2F; 数组的大小    unsigned long size;    &#x2F;&#x2F; 掩码 用于计算索引值    unsigned long sizemask;">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-10-27T06:32:28.000Z">
<meta property="article:modified_time" content="2021-04-04T05:42:02.645Z">
<meta property="article:author" content="邵俊颖">
<meta property="article:tag" content="Redis">
<meta property="article:tag" content="数据库">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://shaojunying.github.io/2020/10/27/Redis%E4%B8%AD%E5%AD%97%E5%85%B8%E7%9A%84%E5%AE%9E%E7%8E%B0/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>Redis中的字典 | Shaojunying's Blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="Shaojunying's Blog" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Shaojunying's Blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">35</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">55</span></a>

  </li>
        <li class="menu-item menu-item-sitemap">

    <a href="/sitemap.xml" rel="section"><i class="fa fa-sitemap fa-fw"></i>站点地图</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

  <a href="https://github.com/shaojunying" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://shaojunying.github.io/2020/10/27/Redis%E4%B8%AD%E5%AD%97%E5%85%B8%E7%9A%84%E5%AE%9E%E7%8E%B0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="邵俊颖">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Shaojunying's Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Redis中的字典
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-10-27 14:32:28" itemprop="dateCreated datePublished" datetime="2020-10-27T14:32:28+08:00">2020-10-27</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-04-04 13:42:02" itemprop="dateModified" datetime="2021-04-04T13:42:02+08:00">2021-04-04</time>
              </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="字典的实现"><a href="#字典的实现" class="headerlink" title="字典的实现"></a>字典的实现</h2><p>字典的底层是基于哈希表实现的,哈希表中的每一个节点保存了字典的一个键值对</p>
<h3 id="哈希表的实现"><a href="#哈希表的实现" class="headerlink" title="哈希表的实现"></a>哈希表的实现</h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">dictht</span>&#123;</span></span><br><span class="line">    <span class="comment">// 数组,存储哈希表中的节点</span></span><br><span class="line">    dictEntry ** table;</span><br><span class="line">    <span class="comment">// 数组的大小</span></span><br><span class="line">    <span class="keyword">unsigned</span> <span class="keyword">long</span> size;</span><br><span class="line">    <span class="comment">// 掩码 用于计算索引值</span></span><br><span class="line">    <span class="keyword">unsigned</span> <span class="keyword">long</span> sizemask;</span><br><span class="line">    <span class="comment">// 该哈希表已有的节点</span></span><br><span class="line">    <span class="keyword">unsigned</span> <span class="keyword">long</span> used;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>哈希表的结构如上所示,其中数组table中的每一项对应哈希表中的一个节点.sizemask的值总是size的值减1,这个属性和哈希值一起决定了新节点应该放在table的哪个地方.</p>
<h3 id="哈希表节点的实现"><a href="#哈希表节点的实现" class="headerlink" title="哈希表节点的实现"></a>哈希表节点的实现</h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">dictEntry</span>&#123;</span></span><br><span class="line">    <span class="comment">// 当前的键</span></span><br><span class="line">    <span class="keyword">void</span> * key;</span><br><span class="line">    <span class="comment">// 当前的值</span></span><br><span class="line">    <span class="keyword">union</span>(</span><br><span class="line">        <span class="keyword">void</span> * val;</span><br><span class="line">        uint64_tu64;</span><br><span class="line">        int64_ts64</span><br><span class="line">    ) v;</span><br><span class="line">    <span class="comment">// 存储下一个节点的指针</span></span><br><span class="line">    dictEntry * next;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>如上是哈希表节点的实现,其中key是键值对的键,v是键值对的值,next指向另一个哈希表节点的指针,用于解决哈希冲突.</p>
<h3 id="字典的实现-1"><a href="#字典的实现-1" class="headerlink" title="字典的实现"></a>字典的实现</h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">dict</span>&#123;</span></span><br><span class="line">    <span class="comment">// 类型特定函数</span></span><br><span class="line">    dictType * type;</span><br><span class="line">    <span class="comment">// 私有数据</span></span><br><span class="line">    <span class="keyword">void</span> * privdata;</span><br><span class="line">    <span class="comment">// 哈希表</span></span><br><span class="line">    dictht ht[<span class="number">2</span>];</span><br><span class="line">    <span class="comment">// rehash进度</span></span><br><span class="line">    <span class="keyword">int</span> trehashidx;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>如上是字典的数据结构</p>
<ul>
<li>类型特定函数<code>type</code>中存储一些指针类型对应的函数实现,例如<code>计算哈希值</code>, <code>复制节点</code>….</li>
<li><code>privdata</code>存储要传给类型特定函数的可选参数</li>
<li>哈希表<code>ht</code>存储两个哈希表,一般只使用ht[0],只有在对ht[0]进行rehash时才会使用ht[1]</li>
<li>rehash进度<code>trehashidx</code>记录当前rehash的进度,没有进行rehash操作时该变量为-1.</li>
</ul>
<h2 id="哈希算法"><a href="#哈希算法" class="headerlink" title="哈希算法"></a>哈希算法</h2><p>找节点在哈希表中位置的过程如下</p>
<ol>
<li>使用类型特定函数计算节点的hash值<code>hash = dict-&gt;type-&gt;hashFunction</code></li>
<li>将hash值与掩码取余获得索引值<code>index = hash &amp; dict-&gt;ht[0]-&gt;sizemask</code></li>
</ol>
<h2 id="解决键冲突"><a href="#解决键冲突" class="headerlink" title="解决键冲突"></a>解决键冲突</h2><p>多个哈希节点使用next指针构成一个链表,遇到冲突时,即向链表中添加节点即可.</p>
<p><em>由于哈希表没有保存链表的尾节点,所以每次添加新结点都是添加在链表的头部.</em></p>
<h2 id="rehash"><a href="#rehash" class="headerlink" title="rehash"></a>rehash</h2><h3 id="rehash的步骤"><a href="#rehash的步骤" class="headerlink" title="rehash的步骤"></a>rehash的步骤</h3><ol>
<li>为ht[1]分配空间<ul>
<li>如果是扩展,那么新容量为第一个大于等于<code>dict-&gt;ht[0].used*2</code>的2的n次方</li>
<li>如果是收缩,那么新容量为第一个大于等于<code>dict-&gt;ht[0].used</code>的2的n次方</li>
</ul>
</li>
<li>为<code>dict-&gt;ht[0]</code>中元素重新计算hash值,将其移动到dict[1]上.</li>
<li>移动完毕之后销毁ht[0]的空间,将ht[0]指向ht[1]所在空间,在ht[1]上创建一个空哈希表,为下一次hash做准备.</li>
</ol>
<h3 id="rehash的时机"><a href="#rehash的时机" class="headerlink" title="rehash的时机"></a>rehash的时机</h3><ul>
<li>扩展<ul>
<li>如果此时正在进行bgsave或者bg_rewrite_aof,且装载因子大于等于5</li>
<li>如果没有进行上述操作,装载因子大于等于1</li>
</ul>
</li>
<li>收缩<ul>
<li>装载因子小于0.1</li>
</ul>
</li>
</ul>
<h4 id="bg-xxx时装载因子大于等于5才保存的原因"><a href="#bg-xxx时装载因子大于等于5才保存的原因" class="headerlink" title="bg_xxx时装载因子大于等于5才保存的原因"></a>bg_xxx时装载因子大于等于5才保存的原因</h4><p>大多数操作系统都采用<code>写时复制</code>的策略来提高子进程的效率,为了减少内存的读写,最大限度节约内存.</p>
<p><code>写时复制</code>:在创建子进程之后,父子进程共用同一片内存区域,只有父子进程有一方要对内存中内容做修改时才复制内存区域的内容.</p>
<h2 id="渐进式rehash"><a href="#渐进式rehash" class="headerlink" title="渐进式rehash"></a>渐进式rehash</h2><p>rehash动作不是一次性完成的,而是分多次、渐进式进行的.通过这种方式将计算量均摊到每次对字典进行增删改查的操作上，避免了集中进行rehas的工作量。</p>
<h3 id="渐进式rehash的步骤"><a href="#渐进式rehash的步骤" class="headerlink" title="渐进式rehash的步骤"></a>渐进式rehash的步骤</h3><ol>
<li>为ht[1]分配空间，使字典同时持有两个哈希表。</li>
<li>将trehashidx置为0，rehash工作正式开始</li>
<li>每次对字典进行增删改查时，除了执行对应操作外，还会将trehashidx索引上的节点rehash到ht[1]上，并将trehashidx加1</li>
<li>随着字典操作的不断进行，待rehash操作完成之后，会将trehashidx重新置为-1，表示rehash操作结束。</li>
</ol>
<h3 id="渐进式rehash注意事项"><a href="#渐进式rehash注意事项" class="headerlink" title="渐进式rehash注意事项"></a>渐进式rehash注意事项</h3><p>渐进式rehash过程中，</p>
<ul>
<li>增加、删除、修改都会在ht[0]和ht[1]两个表上进行。例如：对字典进行查找操作时，会现在ht[0]上作查找，如果查找失败，再去ht[1]上做查找</li>
<li>新增加的键都会添加到ht[1]上，从而保证ht[0]只减不增</li>
</ul>

    </div>

    
    
    

      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/tags/Redis/" rel="tag"><i class="fa fa-tag"></i> Redis</a>
              <a href="/tags/%E6%95%B0%E6%8D%AE%E5%BA%93/" rel="tag"><i class="fa fa-tag"></i> 数据库</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/10/25/Redis%E6%95%B0%E6%8D%AE%E5%BA%93%E7%9A%84%E5%AD%A6%E4%B9%A0/" rel="prev" title="Redis数据库的学习">
      <i class="fa fa-chevron-left"></i> Redis数据库的学习
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/10/28/Java%E4%B8%AD%E7%9A%84Stack/" rel="next" title="Java中的Stack">
      Java中的Stack <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AD%97%E5%85%B8%E7%9A%84%E5%AE%9E%E7%8E%B0"><span class="nav-number">1.</span> <span class="nav-text">字典的实现</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%93%88%E5%B8%8C%E8%A1%A8%E7%9A%84%E5%AE%9E%E7%8E%B0"><span class="nav-number">1.1.</span> <span class="nav-text">哈希表的实现</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%93%88%E5%B8%8C%E8%A1%A8%E8%8A%82%E7%82%B9%E7%9A%84%E5%AE%9E%E7%8E%B0"><span class="nav-number">1.2.</span> <span class="nav-text">哈希表节点的实现</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%AD%97%E5%85%B8%E7%9A%84%E5%AE%9E%E7%8E%B0-1"><span class="nav-number">1.3.</span> <span class="nav-text">字典的实现</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%93%88%E5%B8%8C%E7%AE%97%E6%B3%95"><span class="nav-number">2.</span> <span class="nav-text">哈希算法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%A7%A3%E5%86%B3%E9%94%AE%E5%86%B2%E7%AA%81"><span class="nav-number">3.</span> <span class="nav-text">解决键冲突</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#rehash"><span class="nav-number">4.</span> <span class="nav-text">rehash</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#rehash%E7%9A%84%E6%AD%A5%E9%AA%A4"><span class="nav-number">4.1.</span> <span class="nav-text">rehash的步骤</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#rehash%E7%9A%84%E6%97%B6%E6%9C%BA"><span class="nav-number">4.2.</span> <span class="nav-text">rehash的时机</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#bg-xxx%E6%97%B6%E8%A3%85%E8%BD%BD%E5%9B%A0%E5%AD%90%E5%A4%A7%E4%BA%8E%E7%AD%89%E4%BA%8E5%E6%89%8D%E4%BF%9D%E5%AD%98%E7%9A%84%E5%8E%9F%E5%9B%A0"><span class="nav-number">4.2.1.</span> <span class="nav-text">bg_xxx时装载因子大于等于5才保存的原因</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%B8%90%E8%BF%9B%E5%BC%8Frehash"><span class="nav-number">5.</span> <span class="nav-text">渐进式rehash</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%B8%90%E8%BF%9B%E5%BC%8Frehash%E7%9A%84%E6%AD%A5%E9%AA%A4"><span class="nav-number">5.1.</span> <span class="nav-text">渐进式rehash的步骤</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%B8%90%E8%BF%9B%E5%BC%8Frehash%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9"><span class="nav-number">5.2.</span> <span class="nav-text">渐进式rehash注意事项</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">邵俊颖</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">55</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">35</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/shaojunying" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;shaojunying" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i></a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:shaojunying1@gmail.com" title="E-Mail → mailto:shaojunying1@gmail.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i></a>
      </span>
      <span class="links-of-author-item">
        <a href="https://twitter.com/SHAOJY1999" title="Twitter → https:&#x2F;&#x2F;twitter.com&#x2F;SHAOJY1999" rel="noopener" target="_blank"><i class="fab fa-twitter fa-fw"></i></a>
      </span>
      <span class="links-of-author-item">
        <a href="https://stackoverflow.com/users/10499946/shao-junying" title="StackOverflow → https:&#x2F;&#x2F;stackoverflow.com&#x2F;users&#x2F;10499946&#x2F;shao-junying" rel="noopener" target="_blank"><i class="fab fa-stack-overflow fa-fw"></i></a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        
  <div class="beian"><a href="https://beian.miit.gov.cn/" rel="noopener" target="_blank">京ICP备2020041459号 </a>
  </div>

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">邵俊颖</span>
</div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>

<script src="/js/bookmark.js"></script>




  
  <script>
    (function(){
      var canonicalURL, curProtocol;
      //Get the <link> tag
      var x=document.getElementsByTagName("link");
		//Find the last canonical URL
		if(x.length > 0){
			for (i=0;i<x.length;i++){
				if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){
					canonicalURL=x[i].href;
				}
			}
		}
    //Get protocol
	    if (!canonicalURL){
	    	curProtocol = window.location.protocol.split(':')[0];
	    }
	    else{
	    	curProtocol = canonicalURL.split(':')[0];
	    }
      //Get current URL if the canonical URL does not exist
	    if (!canonicalURL) canonicalURL = window.location.href;
	    //Assign script content. Replace current URL with the canonical URL
      !function(){var e=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi,r=canonicalURL,t=document.referrer;if(!e.test(r)){var n=(String(curProtocol).toLowerCase() === 'https')?"https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif":"//api.share.baidu.com/s.gif";t?(n+="?r="+encodeURIComponent(document.referrer),r&&(n+="&l="+r)):r&&(n+="?l="+r);var i=new Image;i.src=n}}(window);})();
  </script>




  
<script src="/js/local-search.js"></script>













  

  

</body>
</html>
